package com.wc.算法提高课.A第一章_动态规划.背包模型.混合背包问题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/9 19:49
 * @description https://www.acwing.com/problem/content/7/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static int[] f = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        while (n-- > 0) {
            int w = sc.nextInt(), v = sc.nextInt(), s = sc.nextInt();
            if (s == -1) {
                s = 1;
            }
            if (s > 0) {
                for (int k = 1; s > 0; k <<= 1) {
                    if (s < k) {
                        k = s;
                    }
                    s -= k;
                    for (int i = m; i >= k * w; i--) {
                        f[i] = Math.max(f[i], f[i - k * w] + k * v);
                    }
                }
            } else {
                for (int i = w; i <= m; i++) {
                    f[i] = Math.max(f[i], f[i - w] + v);
                }
            }
        }
        out.println(f[m]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
